package com.sc.nft.dto;

import com.sc.nft.exception.GlobalRunTimeException;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.hibernate.validator.constraints.Range;

import javax.validation.constraints.NotBlank;
import java.math.BigDecimal;


@Data
public class EditEquitySharePanelDTO extends IdRequest {

    @ApiModelProperty("名称")
    @NotBlank(message = "模板名称不能为空")
    private String panelName;

    @ApiModelProperty("分红比例")
    @Range(min = 0, max = 1, message = "分红比例只能在0-1之间")
    private BigDecimal shareRatio;

    @ApiModelProperty("版图省级分红比例")
    @Range(min = 0, max = 1, message = "版图省级分红比例只能在0-1之间")
    private BigDecimal metaMapProvinceRatio;

    @ApiModelProperty("版图市级分红比例")
    @Range(min = 0, max = 1, message = "版图市级分红比例只能在0-1之间")
    private BigDecimal metaMapCityRatio;

    @ApiModelProperty("版图区级分红比例")
    @Range(min = 0, max = 1, message = "版图区级分红比例只能在0-1之间")
    private BigDecimal metaMapRegionRatio;


    public void checkRatio() {
        BigDecimal result = shareRatio.add(metaMapProvinceRatio).add(metaMapCityRatio).add(metaMapRegionRatio);
        if (result.compareTo(BigDecimal.ONE) > 0) {
            throw new GlobalRunTimeException("总分润比例合计大于100%");
        }
    }

}
